//
//  ViewController.swift
//  Box
//
//  Created by mn on 2025/4/1.
//

import UIKit
extension UIViewController{
    func toast(_ title: String,deadline: DispatchTime = .now() + 2) {
        let toastView = ToastView()
        toastView.messageLabel.text = title
        view.addSubview(toastView)
        toastView.snp.makeConstraints { make in
            make.center.equalToSuperview()
        }
        DispatchQueue.main.asyncAfter(deadline: deadline) {
            toastView.removeFromSuperview()
        }
    }
}
class ToastView: UIView {
    lazy var messageLabel: UILabel = {
        let label = UILabel()
        label.textColor = .black
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    }()
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupView()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupView()
    }
    
    private func setupView() {
        addSubview(messageLabel)
        backgroundColor = .darkGray
        layer.cornerRadius = 8
        layer.masksToBounds = true
        messageLabel.snp.makeConstraints { make in
            make.edges.equalTo(UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12))
        }
    }
}
